//  this library.
import 'package:flutter/material.dart';
import 'package:hktk_app/util/data_util.dart';
import 'package:hktk_app/util/font_util.dart';
import 'package:hktk_app/util/view_util.dart';

/// 购买提示页面
class PurchaseTipsWidget extends StatelessWidget {
  /// 提示语句
  final String? tips;

  /// 是否显示遮罩
  final bool? showMasking;

  /// 栏目id
  final String columnId;

  const PurchaseTipsWidget({
    super.key,
    this.tips = "购买立即解锁全部章节练习",
    this.showMasking = false,
    required this.columnId,
  });

  @override
  Widget build(BuildContext context) {

    // 获取底部安全边距
    var of = MediaQuery.of(context);
    var bottom = of.padding.bottom;
    var width = of.size.width;
    var height = of.size.height - of.padding.top - bottom - 88 - 96;
    return Positioned(
      bottom: bottom,
      child: Column(
        mainAxisAlignment: MainAxisAlignment.end,
        children: [
          if (showMasking!) _masking(width, height),
          _tips(width, context),
        ],
      ),
    );
  }

  /// 提示组件
  _tips(double width, BuildContext context) {
    return Container(
      width: width,
      height: 96,
      padding: EdgeInsets.symmetric(vertical: 21, horizontal: 30),
      decoration: const BoxDecoration(color: colorBlack6),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Text(
            tips!,
            style: FontUtil.fontWhile1(28, fontWeight: FontWeight.w400),
          ),
          _btn(context),
        ],
      ),
    );
  }

  /// 未购买按钮
  _btn(BuildContext context) {
    return GestureDetector(
      onTap: () {
        packageFun(
          context: context,
          columnId: columnId,
          dataModel: dataUtilComm.dataModel,
        );
      },
      child: Container(
        width: 140,
        height: 54,
        // padding: EdgeInsets.symmetric(vertical: 10, horizontal: 22),
        decoration: BoxDecoration(
          borderRadius: BorderRadius.all(Radius.circular(27)),
          gradient: const LinearGradient(
            colors: [
              colorBlue20,
              colorBlue21,
            ],
            begin: Alignment.topLeft,
            end: Alignment.bottomRight,
          ),
        ),
        child: Center(
          child: Text(
            "马上购买",
            style: FontUtil.fontWhile1(24, fontWeight: FontWeight.w500),
          ),
        ),
      ),
    );
  }

  /// 遮罩
  _masking(double width, double height) {
    return Container(
      width: width,
      height: height,
      decoration: const BoxDecoration(color: Colors.transparent),
    );
  }
}
